package cn.faifai.tagapi.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Set;

@Entity
// 审计功能，对数据的创建、最后更新时间以及创建、最后操作人进行记录
@EntityListeners(AuditingEntityListener.class)//开启审计监听
@Table(name = "tag")
//@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class)
@Getter
@Setter
@EqualsAndHashCode(exclude = {"IFiles"})
public class Tag extends BaseEntity{
    @Id
    @Column(name = "id")
    @GeneratedValue(generator = "snowflake")
    @GenericGenerator(name = "snowflake", strategy = "cn.faifai.framework.config.jpa.SnowFlakeIdGenerator")
    private Long id;

    @Column(name = "parent_id")
    private Long parentId;

    @Column(name = "name")
    private String name;

    // 使用 @ManyToMany 注解定义多对多关系
    // mappedBy 属性指定关系的维护端在 file 实体中  关联的成员变量集合名为 tags
    @ManyToMany(mappedBy = "tags", cascade = {CascadeType.PERSIST, CascadeType.MERGE},fetch = FetchType.LAZY)
    @JsonIgnore
    private Set<IFile> IFiles;
}
